package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.CaseService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/case")
@CrossOrigin
@Api(value = "案例管理", description = "案例管理")
public class CaseController {

    private final CaseService caseService;

    public CaseController(CaseService caseService) {
        this.caseService = caseService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增案例接口",notes = "新增案例接口")
    public LogicResponse save(@RequestBody @Validated CaseCreateDTO caseCreateDTO) {
        caseService.save(caseCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/reply")
    @ApiOperation(value = "回复信息接口",notes = "回复信息接口")
    public LogicResponse reply(@RequestBody @Validated CaseReplyDTO caseReplyDTO) {
        caseService.reply(caseReplyDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/set/read")
    @ApiOperation(value = "设置已读信息接口",notes = "设置已读信息接口")
    public LogicResponse setRead(@RequestBody @Validated CaseIdListDTO caseIdListDTO) {
        caseService.setRead(caseIdListDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取案例信息列表",notes = "获取案例信息列表")
    public LogicResponse getCaseList(@RequestBody @Validated CaseQueryDTO caseQueryDTO) {
        return LogicResponse.success(caseService.getCaseList(caseQueryDTO));
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查看单个案例详情")
    public LogicResponse detail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(caseService.getCaseDetail(baseIdDTO));
    }

    @PostMapping("/set/use")
    @ApiOperation(value = "设置已采纳信息接口",notes = "设置已采纳信息接口")
    public LogicResponse setAdopted(@RequestBody @Validated CaseIdListDTO caseIdListDTO) {
        caseService.setAdopted(caseIdListDTO);
        return LogicResponse.success("success");
    }

}
